﻿using System;

namespace AlgorytmyGenetyczne
{
    public class Osobnik
    {
        public double Ocena { get; set; }
        public Genotyp Genotyp { get; set; }

        public Osobnik()
        {
            Genotyp = new Genotyp();
        }

        public Osobnik(Osobnik osobnik)
        {
            Genotyp= new Genotyp(osobnik.Genotyp);
            Ocena = osobnik.Ocena;
        }

        public bool Equals(Osobnik other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Genotyp, Genotyp);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Osobnik)) return false;
            return Equals((Osobnik) obj);
        }

        public override int GetHashCode()
        {
            return (Genotyp != null ? Genotyp.GetHashCode() : 0);
        }

        public static bool operator ==(Osobnik left, Osobnik right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Osobnik left, Osobnik right)
        {
            return !Equals(left, right);
        }

        public override string ToString()
        {
            return Ocena.ToString();
        }
    }
}
